package com.myframework.daoImpl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.myframework.dao.UserDao;
import com.myframework.entity.User;
import com.myframework.util.BaseDaoImpl;

@Repository
public class UserDaoImpl extends BaseDaoImpl<User, String> implements UserDao {
	
	@Autowired
	SessionFactory sf;
	
	public User insertUser(User user) {
		Session session = sf.openSession();
		Transaction tx = session.beginTransaction();
		
		session.save(user);
		
		Query query = session.createQuery(" from User where id = ? ");
		query.setParameter(0, user.getId());
		user = (User) query.getSingleResult();
		tx.commit();
		session.close();
		
		return user;
	}

}
